﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evan.Security
{
    public static class SefaTip
    {
        public static string ReturnErrorMsg(string msg)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<!DOCTYPE html>");
            sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            sb.Append("<head>");
            sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
            sb.Append("<title>" + msg + "</title>");
            sb.Append("<style type=\"text/css\">");
            sb.Append("body { margin:0; height:100%; background-color:#cf3326; font-family:SegoeUI,\"Helvetica Neue\",Helvetica,Arial,sans-serif; font-weight: 100 }");
            sb.Append("#box { margin:0 auto;width:600px; height:auto; margin-top:15%; color:#fff; }");
            sb.Append("#box a { color:#fff; }");
            sb.Append("#box #title { font-size:40px; margin-bottom:30px; }");
            sb.Append("#box #subtitle { font-size:30px; margin-bottom:30px; }");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("<div id=\"box\">");
            sb.Append("<div id=\"title\">" + msg + "</div>");
            sb.Append("<div id=\"subtitle\">服务器已经阻止了您当前的请求</div>");
            sb.Append("<div><a href=\"javascript:history.back();\">返回前一页</a></div>");
            sb.Append("<br/><br/><div style=\"font-size:10px;text-align: right;\">Power By Safe Checker Process</div>");
            sb.Append("</div>");
            sb.Append("</body>");
            sb.Append("</html>");
            return sb.ToString();

        }

        public static string ReturnBlackScreen(string title, List<string> msgList)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<!DOCTYPE html>");
            sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            sb.Append("<head>");
            sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
            sb.Append("<title>" + title + "</title>");
            sb.Append("<style type=\"text/css\">");
            sb.Append("body { background-color:#000000; font-family:MicroSoft YaHei,SegoeUI,\"Helvetica Neue\",Helvetica,Arial,sans-serif; font-weight: 100; -webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;    }");
            sb.Append("#box { color:#fff; margin: 15% auto;width: 50%;border: 0px solid #fff;padding: 20px;min-height: 300px;min-width: 400px;max-width: 800px; }");
            sb.Append("#box .info-line { font-size:12px; margin-bottom:5px; word-break: break-all;}");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body ondragstart=\"window.event.returnValue=false\" oncontextmenu=\"window.event.returnValue=false\" onselectstart=\"event.returnValue=false\">");
            sb.Append("<div id=\"box\">");
            sb.Append("<div style=\"\">");
            sb.Append("<div class=\"info-line\">Evan.Core  ( Build Command )</div>");
            sb.Append("<div class=\"info-line\">Copyright © " + DateTime.Now.Year + " Evan.CMS  , Inc. All rights reserved.</div>");
            foreach (string item in msgList)
            {
                sb.Append("<div class=\"info-line\">" + item + "</div>");
            }
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("</body>");
            sb.Append("</html>");
            return sb.ToString();
        }

        public static string ReturnBlueScreen(string msg, Exception ex)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<!DOCTYPE html>");
            sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            sb.Append("<head>");
            sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
            sb.Append("<title>" + msg + "</title>");
            sb.Append("<style type=\"text/css\">");
            sb.Append("body { margin:0; height:100%; background-color:#1070aa; font-family:SegoeUI,\"Helvetica Neue\",Helvetica,Arial,sans-serif; font-weight: 100 }");
            sb.Append("#box { margin:0 auto;width:700px; height:auto; margin-top:8%; color:#fff; }");
            sb.Append("#box a { color:#fff;cursor:pointer; }");
            sb.Append("#box #face { font-size:90px;margin-bottom:30px; }");
            sb.Append("#box #title { font-size:40px; margin-bottom:30px; }");
            sb.Append("#box #subtitle { font-size:30px; margin-bottom:30px; }");
            sb.Append("#box #reason { display:none;margin-top:20px; }");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("<div id=\"box\">");
            sb.Append("<div id=\"face\">(っ °Д °;)っ</div>");
            sb.Append("<div id=\"title\">" + msg + "</div>");

            if (ex == null || ex.InnerException == null)
            {
                sb.Append("<div id=\"subtitle\">" + ((ex.Message == null) ? "应用程序中的服务器错误" : ex.Message) + "</div>");
                sb.Append("<div><a onclick=\"javascript:document.getElementById('reason').style.display='block';\">查看原因</a></div>");
                sb.Append("<div id=\"reason\">" + ((ex.Message == null) ? "未知错误<br/>无法显示页面，因为发生内部服务器错误。" : ex.Message) + "</div>");
            }
            else
            {
                sb.Append("<div id=\"subtitle\">应用程序中的服务器错误</div>");
                sb.Append("<div><a onclick=\"javascript:document.getElementById('reason').style.display='block';\">查看原因</a></div>");
                sb.Append("<div id=\"reason\">" + (ex.InnerException.Message + "<br/>" + ex.InnerException) + "</div>");
            }
            sb.Append("<br/><br/><div style=\"font-size:10px;text-align: right;\">Power By Error Handler Process</div>");
            sb.Append("</div>");
            sb.Append("</body>");
            sb.Append("</html>");
            return sb.ToString();
        }

        

    }
}
